# To change this template, choose Tools | Templates
# and open the template in the editor.

module MailParser

  def parse_content(email)
    content_plain = nil
    content_html = nil
    if email.multipart? then
      email.parts.each do |m|
        if m.multipart? then
          m.parts.each do |mm|
            if mm.content_type == 'text/plain' then
              content_plain = mm.body
            end
            if mm.content_type == 'text/html' then
              content_html = mm.body
            end
          end
        else
          if m.content_type == 'text/plain' then
            content_plain = m.body
          end
          if m.content_type == 'text/html' then
            content_html = m.body
          end
        end
      end
    else
      content_plain = email.body
      content_html = email.body
    end
    {:html => content_html, :plain => content_plain}
  end
end
